/**
 * Created by ZE-C on 2017/8/20.
 */

import {Component} from "@angular/core";
// import {Observable} from "rxjs/Observable";
// import {Observable} from 'rxjs'
import "rxjs/add/observable/interval";
import "rxjs/add/observable/from";
import "rxjs/add/observable/of";
import "rxjs/add/operator/do";
import "rxjs/add/operator/pluck";
import "rxjs/add/operator/distinct";
import "rxjs/add/operator/filter";
import "rxjs/add/operator/map";
import "rxjs/add/operator/mapTo";
import "rxjs/add/operator/switchMap";
import "rxjs/add/operator/concatMap";
import "rxjs/add/operator/debounceTime";
import "rxjs/add/operator/distinctUntilChanged";
import "rxjs/add/operator/concat";
import "rxjs/add/operator/merge";
import "rxjs/add/operator/mergeMap";
import "rxjs/add/operator/take";
import "rxjs/add/observable/fromEvent";
import {SelectItem} from "primeng/primeng";

@Component(
  {
    selector: 'rxjs-page',
    templateUrl: 'rxjs.component.html'
  }
)

export class RxjsPageComponent {
    public datas:SelectItem[] = [];
    selectedValue: string;

    constructor(){
      let i  = 0;
      for( i=0; i<20; i++ ){
        this.datas.push({label:'a'+i,value:'王小明'+i})
      }
    }

}

/* rxjs
// rxjs
export class RxjsPageComponent {

  input3 = new FormControl();

  clock: number = 0;
  subject = new Subject<string>();
  observable = this.subject.asObservable();

  constructor(private service: Myervice) {

    /!*
    this.input3.valueChanges
      .do(res => console.log('server:'+res))
      .debounceTime(1000)
      .distinctUntilChanged()
      .subscribe( res => console.log('client:'+res) )
*!/
/!*    this.observable
      .do( res => console.log('server:'+res) )
      .map(res => res.toUpperCase())
      .subscribe( res => console.log('client:'+res) )*!/

    /!*   Observable.interval(1000)
     .subscribe(
     res => {
     this.clock = res
     }
     );

     Observable.fromEvent(document,'click').subscribe(
     res => { console.log(res) }
     )*!/

  }

  onKeyup(event){
    console.log(event.target.value);
    console.log(event.key)
  }

  onInput($event) {
    this.subject.next($event.target.value)
  }

  onClick2(ev){

  }

  onClick() {

    // mergeMap
    // Observable.from(['a','b','c'])
    Observable.interval(100).take(3)
      .mergeMap( s1 => Observable.from([1,2,3]) )
      // .mergeMap( s1 => Observable.interval(100).take(20)  )
      .subscribe(res=>console.log(res))

    /!*!// switchMap
    // 如果source1发射和source2发射同时进行 source1结束了， source2也停止
    Observable.from(['a','b','c'])
      .switchMap( s1 => Observable.interval(100).take(20) )
      .subscribe(res=>console.log(res))*!/

/!*    //concatMap
    Observable.from(['a','b','c'])
      .concatMap( s1 => Observable.from([s1,1,2,3]) )
      .subscribe(res=>console.log(res))*!/

    // concat
/!*    Observable.from(['a','b','c'])
      .concat( Observable.from([1,2,3]) )
      .subscribe(res=>console.log(res))*!/


   /!* let input = <HTMLInputElement>document.getElementById('inputabc');
    console.log(input.value)*!/

    /!*  this.service.get('contacts').subscribe(
     res => {
     console.log(res)
     }
     )*!/
  }


}*/
